/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
*  \class	CLine
*  \author 	Jari Saarinen
*  \date 	Thu Jun 15 22:16:18 2006

* The Class version from the former linelib 
*  \version: 0.1  
*/

#ifndef C_LINE_H
#define C_LINE_H

#include "TCoord2D.h"
#include "TLine.h"
#include "TAngle.h"
#include "LNMdatastructs.h"


class CLine
{
private: 
protected:
	TLine line;

public:
	CLine();
	~CLine();

	/**
	* Sets the TLine to CLine
	*/
	void setLine(TLine l);

	/**
	* Set the line using line start and end points
	*/
	
	void setLine(float x1, float y1, float x2, float y2);
	
	/**
	* Returns the line structure of this line
	*/
	TLine getTLine();
	
	/**
	* The angle of the line. The angle is calculated from starting point (x1,y1)
	* towards end point (x2,y2)
	* @return TAngle class 
	*/
	TAngle getLineAngle();
	
	/**
	* Returns the length of the line squared
	*/

	float getLineLengthSquared();
	/**
	* Returns the length of the line
	*/
	float getLineLength();
	
	/**
	* Calculates the distance of the point (x,y) from line L
	* @param p	The 2D-point from where the distance is calculated
	* @return distance if succesful, else -1
	*/
	float pointDistanceFromLine(TCoord2D p);

	/** 
	* Returns the  angle difference between this line and another line 
	* @param l2		CLine
	**/
	TAngle angleDiff(CLine l);
	
	/**
	* Rotates line around coordinate P
	* @param P Coordinate around which the rotation is done
	* @param alpha rotation angle
	*/
	void rotate(TCoord2D P, float alpha);
	
	/**
	* checks if coordinate P belongs to the Line
	* Returns 1 if it does 0 if not
	*/
	int isInLine(TCoord2D P);
	
	/**
	* Calculates point (coordinate) from the TLine line, which is closest 
	* to the TCoord2D pos
	*
	* returns the TCoord2D. 
	**/  				
	TCoord2D shortestPointFromLine(TCoord2D pos);
};          


#endif


